using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Sec_scan漏洞扫描系统.Sec_Service
{
    /// <summary>
    /// 代理服务 默认使用太阳代理 代理地址：https://www.tyhttp.com/getapi/
    /// </summary>
    public class Sec_Proxx_Service
    {
        /// <summary>
        /// 太阳代理的方式
        /// </summary>
        /// <param name="proxys"></param>
        /// <returns></returns>
        public static string ProxySettring(string proxys)
        {
            string proxyServer = "";//host:port, 例(http://1.2.3.4:7777), host可以是域名或者ip,port是代理端口号
            var proxy = new WebProxy(proxyServer);
            HttpClientHandler httpClientHandler = new HttpClientHandler()
            {
                Proxy = proxy
            };
            var httpCient = new HttpClient(httpClientHandler);
            // 增加头部
            httpCient.DefaultRequestHeaders.Add("Header-Key", "header-vaule");
            Sec_Proxx_Service sec_Proxx = new Sec_Proxx_Service();
            sec_Proxx.testGet(httpCient);//使用代理
            return proxys;
        }
        // 测试get请求
        public void testGet(HttpClient httpClient)
        {
            String targetUrl = "http://httpbin.org/get";
            var httpResult = httpClient.GetStringAsync(targetUrl).Result;
        }
        // 测试post请求
        public void testPost(HttpClient httpClient)
        {
            String targetUrl = "http://httpbin.org/post";
            List<KeyValuePair<string, string>> formData = new List<KeyValuePair<string, string>>();
            formData.Add(new KeyValuePair<string, string>("key1", "vaule1"));
            formData.Add(new KeyValuePair<string, string>("key2", "vaule2"));
            var formContent = new FormUrlEncodedContent(formData.ToArray());
            var responseMsg = httpClient.PostAsync(targetUrl, formContent).Result;
            var httpResult = responseMsg.Content.ReadAsStringAsync().Result;
        }
    }
}
